{layout name="common/base" }
<div class="layui-form layuimini-form">
    <input type="text" hidden value="<?php echo $product_id;?>" name="product_id"><!-- 商品id -->
    <input type="text" hidden value="<?php echo $id;?>" name="id"><!-- 答案id -->
    <div class="layui-form-item">
        <label class="layui-form-label required">结果标题</label>
        <div class="layui-input-block" style="width:375px;">
            <input type="text" name="title" lay-verify="required" lay-reqtext="标题不能为空" placeholder="请输入标题" value="{$data.title}" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">分析结果</label>
        <div class="layui-input-block" style="width: 375px;">
            <textarea id="editor" style="display: none;" name="content">{$data.content}</textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">最小值</label>
        <div class="layui-input-block" style="width:375px;">
            <input type="number" name="minscore" placeholder="请输入最小值" value="{$data.minscore}" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">最大值</label>
        <div class="layui-input-block" style="width:375px;">
            <input type="number" name="maxscore" placeholder="请输入最大值" value="{$data.maxscore}" class="layui-input">
        </div>
    </div>
    <!--<div class="layui-form-item">
        <label class="layui-form-label required">排序</label>
        <div class="layui-input-block" style="width:375px;">
            <input type="number" name="sort" lay-verify="required" value="1" class="layui-input">
        </div>
    </div>-->
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="saveBtn">确认修改</button>
        </div>
    </div>
</div>
<script src="__PUBLIC__/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="__PUBLIC__/js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script src="__PUBLIC__/js/commons.js" charset="utf-8"></script>
<script type="text/javascript">
    var url = '/admin/Answer/edit';
    layui.use(['form','upload', 'layedit','table', 'laydate','element'], function(){
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$,
            layedit = layui.layedit
            ,laydate = layui.laydate
            , upload = layui.upload
            ,element = layui.element
            ,table = layui.table;

        function goback(data){
            if(data.code=='1') window.history.go(-1);
        }
        //上传图片,必须放在 创建一个编辑器前面
        layedit.set({
            uploadImage: {
                url: "{:url('/admin/Image/uploadEditor')}",//接口url
                type: 'post'
            }
        });
        //建立编辑器
        var lb = layedit.build('editor', {
            height: 400 //设置编辑器的高度
        });

        form.on('submit(saveBtn)', function(data){
            //获取编辑器内容
            data.field.content=layedit.getContent(lb);
            var jsons = JSON.stringify(data.field);
            console.log(jsons);
            $.ajax({
                url: url,
                data: data.field,
                type: 'POST',
                dataType: "json",
                //contentType: "application/json; charset=utf-8",
                success: function(res) {
                    //console.log("fffffff");console.log(res);
                    layer.msg(res.message, {
                        icon: 1,
                        time: 2000 //2秒关闭（如果不配置，默认是3秒）
                    }, function(){
                        if(res.status < 1){
                            // 关闭弹出层
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.location.reload();//刷新父页面，注意一定要在关闭当前iframe层之前执行刷新
                            parent.layer.close(index); //再执行关闭
                        }
                    });
                },
                error: function(res) {
                    //return   err(res)
                }
            });
            return false;
        });
    });
</script>
